package com.hyg.module_third_party_demo.activity;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.alibaba.android.arouter.core.LogisticsCenter;
import com.alibaba.android.arouter.facade.Postcard;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.facade.callback.NavCallback;
import com.alibaba.android.arouter.launcher.ARouter;
import com.hyg.lib_common.constant.Constants;
import com.hyg.module_third_party_demo.R;
import com.hyg.module_third_party_demo.entity.User;
import com.hyg.module_third_party_demo.litepal.DataModule.Option;

/**
 * @description Arouter路由demo界面
 * @author visitant
 * @time 2020/11/13 16:38
 */
@Route(path = Constants.PATH_ACTIVITY_MODULE_DEMO_AROUTER)
public class ArouterActivity extends AppCompatActivity {

    TextView textView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_arouter);
        textView = findViewById(R.id.show_msg_tv);
    }

    public void onBack(View view) {
        finish();
    }


    /**
     * @description 带参跳转
     * @author visitant
     * @time 2020/11/13 16:39
     */
    public void onNext1(View view) {
        Bundle bundle = new Bundle();
        bundle.putString("name", "测试");
        User user = new User("123", 20, false);
        ARouter.getInstance().build(Constants.PATH_ACTIVITY_MODULE_DEMO_AROUTER_NEXT)
                .withLong("type", 0)
                .withBundle("params", bundle)
                .withObject("object", user)
//              .navigation();
                .navigation(this, new NavCallback() {
                    @Override
                    public void onArrival(Postcard postcard) {

                    }

                    @Override
                    public void onInterrupt(Postcard postcard) {
                        super.onInterrupt(postcard);
                    }
                });
    }

    /**
     * @description startActivityForResult
     * @author visitant
     * @time 2020/11/13 16:39
     */
    public void onNext2(View view) {
        Postcard postcard = ARouter.getInstance().build(Constants.PATH_ACTIVITY_MODULE_DEMO_AROUTER_NEXT2);
        LogisticsCenter.completion(postcard);
        Class<?> destination = postcard.getDestination();
        Intent intent = new Intent(this, destination);
        startActivityForResult(intent, 200);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 200) {
            Bundle bundle = data.getExtras();
            textView.setText("onActivityResult: return data= " + bundle.getString("params"));
        }
    }











}